package com.aaron.dao;

import com.aaron.io.Resources;
import com.aaron.pojo.User;
import com.aaron.sqlSession.SqlSession;
import com.aaron.sqlSession.SqlSessionFactory;
import com.aaron.sqlSession.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class UserDao implements IUserDao{


    @Override
    public List<User> findAll() throws Exception{
        InputStream inputStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();

        List<User> users = sqlSession.selectList("user.selectOne");
        for (User user : users) {
            System.out.println(user);
        }
        return users;
    }

    @Override
    public User findByCondition(User user) throws Exception{
        InputStream inputStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        User user2 = sqlSession.selectOne("user.selectOne", user);
        return user2;
    }

    @Override
    public Integer insert(User user) throws Exception{
        InputStream inputStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        User user2 = sqlSession.selectOne("user.selectOne", user);
        return null;
    }

    @Override
    public Integer updateById(User user) throws Exception {
        return null;
    }

    @Override
    public Integer deleteById(int i) {
        return null;
    }


    @Override
    public Object insert(Object object) {
        return null;
    }
}
